package com.gjy.nacos.server.service.impl;

import com.gjy.nacos.server.domain.User;
import com.gjy.nacos.server.repository.UserRepository;
import com.gjy.nacos.server.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.List;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-03-08 11:08:59
 */
@Service
@Transactional(rollbackFor = SQLException.class)
public class UserServiceImpl implements UserService {

    @Resource
    private UserRepository userRepository;

    public final User saveUser(User user) {
        return userRepository.save(user);
    }

    public Integer saveUser(User user, Boolean type) {
        if (type) {
            return userRepository.saveUser(user.getName(), user.getEmail(), user.getAge(), user.getId());
        } else {
            return userRepository.save(user).getId().intValue();
        }
    }

    public List<User> findUsersGtAge(BigDecimal age) {
        return userRepository.findUsersGtAge(age);
    }

    public Integer deleteUserById(Long id) {
        return userRepository.deleteUserNatById(id);
    }

    public Integer updateUserEmailById(String email, Long id) {
        return userRepository.updateUserEmailById(email, id);

    }

}
